package com.chen.paymentdemo.controller;

import com.chen.paymentdemo.entity.OrderInfo;
import com.chen.paymentdemo.enums.OrderStatus;
import com.chen.paymentdemo.service.OrderInfoService;
import com.chen.paymentdemo.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Y·C
 * @version 1.0.0
 * @ClassName OrderInfoController.java
 * @Description TODO
 * @createTime 2023年07月24日 15:30:00
 */
@RestController
@CrossOrigin
@RequestMapping("/api/order-info")
@Api(tags = "商品订单管理")
public class OrderInfoController {

    @Resource
    private OrderInfoService orderInfoService;

    @ApiOperation("获取订单列表")
    @GetMapping("/list")
    public R list(){
       List<OrderInfo> list = orderInfoService.listOrderByCreateTimeDesc();
        return R.ok().data("list",list);
    }

    @ApiOperation("查找订单状态")
    @GetMapping("/query-order-status/{orderNo}")
    public R queryOrderStatus(@PathVariable String orderNo){
        String orderStatus = orderInfoService.getOrderStatus(orderNo);
        if (OrderStatus.SUCCESS.getType().equals(orderStatus)){
            return R.ok().setMsg("支付成功");
        }
        return R.ok().setCode(101).setMsg("支付中...");
    }




}
